<template>
	<view> 
	    <!-- 卡通权益会员-弹窗（未开通会员且配置该业务时显示）@updateMinVipFlag='updateMinVipFlag'-->
	    <benefit-vip-min @click="onceClick" :saleFiffVip='payTotalInfo.saleFiffVip' v-show="storeCardInfo.memberIsPayCard === '0' && storeCardInfo.isPayCard ==='1' && !payTotalInfo.openVip"></benefit-vip-min>
 
		<!-- 组件 购物车栏  z-index: 10076 高于 u-popup的10075  #E6E6E6 -->
		<view class="chxy-row-ac good-cart-view" :class="themeInfo == '001' ? 'qunqing' : 'other'" :style="{'zIndex': zIndexNum}">
			<view class="carr-num-view" @click="openShowGoods">
				<image v-if="themeInfo == '001' " src="https://jtmc.oss-cn-hangzhou.aliyuncs.com/h5-uniapp/h5-order/cart-pink.png" style="width: 72rpx;height: 72rpx;"></image>
				<image v-else  src="https://oss.jtmckj.com/h5-uniapp/tgx/order/cart-pink.png" style="width: 72rpx;height: 72rpx;"></image>
				<view class="num-badge">
					<up-badge :bgColor="themeInfo == '001' ? '#28FFD9' : '#ff3333' " :class="themeInfo == '001' ? 'qunqing' : 'other'" :value="badgeValue"></up-badge>
				</view>
			</view>
			<view class="carr-content-view chxy-row-ac">
				<view class="fix-w"></view>
				<view>
					<text class="dol" :class="themeInfo == '001' ? 'qunqing' : 'other'">￥</text> 
					<!-- 已开通vip -->
					<text class="dol-money" :class="themeInfo == '001' ? 'qunqing' : 'other'" v-if="storeCardInfo.memberIsPayCard === '1' ">{{(totalVipPrice) }}</text>
					<!-- 刚开通vip -->
					<text class="dol-money" :class="themeInfo == '001' ? 'qunqing' : 'other'" v-else-if="storeCardInfo.memberIsPayCard === '0' && payTotalInfo.openVip">{{numAddFun(totalVipPrice,payTotalInfo.totalPayVip)}}</text>
					<!-- 未开通vip 且 无权限开通vip -->
					<text class="dol-total-money" :class="themeInfo == '001' ? 'qunqing' : 'other'" v-else >{{totalPrice}}</text>
				</view>
				<view class="fix-center-w"></view> 
				<view class="open-vip-view" v-if="storeCardInfo.memberIsPayCard === '1' || payTotalInfo.openVip" >
					<text> 
						<text class="vip-total">￥{{totalPrice}}</text>
						<text class="vip-money">已优惠{{payTotalInfo.saleFiffVip || 0 }}元</text>
					</text>
					<view class="vip-badge"> 
						共{{badgeValue}}件 
					</view>
				</view>
				<view v-else class="dol-total-j">
					共{{badgeValue}}件 
				</view>
				<view class="fix-end-w"></view>
			</view>
			<view @click="toPay" :class="handleFlag ? 'cart-pay' : 'cart-pay-stop' ">
				去结算
			</view> 
		</view>

		<!-- 购物车弹窗 -->
		<u-popup :show="showCartPop" @close="showCartPop = false" :round="10">
			<view class="cart-pop">
				<!-- 1==2 是否开通权益vip 此处样式需调整 -->
				<view class="cart-pop-view" :style="(storeCardInfo.memberIsPayCard == '0' && storeCardInfo.isPayCard =='1' && themeInfo != '005' && themeInfo != '006') ? 'padding-bottom: 208rpx;' : 'padding-bottom: 108rpx;' "> 
					<view @tap="$u.throttle(clearGoods, 500)" class="chxy-row-ac-end clear-view">
						<image src="https://oss.jtmckj.com/wmp/images/home/order/i_clear.png" class="clear-icon"></image>
						<view class="clear-name">清空购物车</view>
					</view>
					<view class="pop-goods-view">
						<!-- 购物车商品列表 -->
						<view class="chxy-row" v-for="(item,index) in goodsList" :key="index + item.id">  
						    <!-- 套餐 -->
						    <view v-if="item.packageOthList">
							  <view class="pop-package-view chxy-row" v-for="(packitem,packindex) in item.packageOthList" :key="packindex + packitem.id  + JSON.stringify(packitem.priceList)">
								<image class="pop-public-img" v-if="packitem.attachment" :src="packitem.attachment" mode="aspectFill"></image>
								<image class="pop-public-img" v-else src="https://jtmc.oss-cn-hangzhou.aliyuncs.com/public/other/icon-default.png" ></image> 
								<view class="w-20"></view>
								<view class="pop-flavor-view">
									<view class="pop-sub-name">{{packitem.goodsName}}</view>
									<view class="h-16"></view>
									<view class="pop-flavor" >
										 {{ filterPackFlavor(packitem)}}
									</view>
									<view class="h-16"></view>
									<view class="chxy-row-bt pop-price-num">
										<view>￥{{packitem.salePrice}}</view>
										<view><order-number-box :max="9999999" :min="0" v-model="packitem.qty" @change="valChangePack($event,packitem,index,item)"/></view>
									</view>
									<view class="h-26"></view>
								</view>
							  </view>
							</view>
							
							<!-- 规格 -->
							<view v-if="item.specsOthList"> 
							  <view class="pop-specs-view chxy-row" v-for="(specsitem,specsindex) in item.specsOthList" :key="specsindex + specsitem.id + JSON.stringify(specsitem.priceList)">
								<image v-if="specsitem.attachment" :src="specsitem.attachment" class="pop-public-img" mode="aspectFill"></image>
								<image v-else src="https://jtmc.oss-cn-hangzhou.aliyuncs.com/public/other/icon-default.png" class="pop-public-img"></image> 
								<view class="w-20"></view>
								<view class="pop-flavor-view">
									<view class="pop-sub-name">{{specsitem.goodsName}}</view>
									<view class="h-16"></view>
									<text class="pop-flavor-specs">   
										<text v-if="Array.isArray(specsitem?.goodsFlavor) && specsitem?.goodsFlavor.length > 0">
											<text v-for="(gfitem,gfindex) in specsitem.goodsFlavor" :key="gfindex">
												<text v-for="(defitem,defindex) in gfitem.defCheck" :key="defindex">
													<text>{{defitem}}、</text> 
												</text>
											</text>
										</text> 
										<text v-for="(priceitem,priceindex) in specsitem.priceList" :key="priceindex">
											<text v-if="priceitem.check">{{priceitem.uomName}} </text>
										</text>
									</text>
									<view class="h-16"></view>
									<view class="chxy-row-bt pop-specs-p-n">
										<view>￥{{ specsHandlePrice(specsitem) }}</view>
										<view> <order-number-box :max="9999999" :min="0" v-model="specsitem.qty" @change="valChangeSpecs($event,specsitem,specsindex,item)" /></view>
									</view>
									<view class="h-26"></view>
								</view>
							  </view>
							</view> 
							
							<!-- 单品 -->
							<view v-else class="chxy-row pop-single-view">
								<image v-if="item.attachment" :src="item.attachment" class="pop-public-img" mode="aspectFill"></image>
								<image v-else src="https://jtmc.oss-cn-hangzhou.aliyuncs.com/public/other/icon-default.png" class="pop-public-img"></image> 
								<view class="w-20"></view>
								<view class="pop-flavor-view">
									<view class="pop-sub-name">{{item.goodsName}}</view>
									<view class="h-16"></view>
									<view class="pop-flavor">{{item?.flavor}}</view>
									<view class="h-16"></view>
									<view class="chxy-row-bt pop-single-p-n">
										<view>￥{{item.salePrice}}</view>
										<view> <order-number-box :max="9999999" :min="0" v-model="item.qty" @change="valChange($event,item,index,goodsList)" /></view>
									</view>
									<view class="h-26"></view>
								</view>
							</view>
							
						</view>

					</view>
					<view class="h-20 bc-fix-20"></view>
					<view class="h-20 bc-fix-20" v-show='payTotalInfo.openVip'></view>
					<benefit-vip :saleFiffVip='payTotalInfo.saleFiffVip' v-show="storeCardInfo.memberIsPayCard === '0' && storeCardInfo.isPayCard ==='1'" @updateVipFlag='updateVipFlag' ref="benefitVipRef"></benefit-vip>
				</view>
			</view>
		</u-popup> 

	</view>
</template>

<script setup>
	import { ref, reactive, onMounted, nextTick, defineEmits, defineExpose,defineProps } from 'vue';
	import { initTableInfo,updateTableInfo,numMultiFun,numAddFun,numDiffFun } from "@/until/tools.js"
	import { useCartStore } from '@/store/cart.js'; // import { useTableStore } from '@/store/table.js'; const storeTable = useTableStore();
	const storeCart = useCartStore();
	const emit = defineEmits(['goodsItemChange','updat:zIndexNum','clearCart']); 
	
	const themeInfo = ref(uni.getStorageSync('themeInfo')?.type)

	const props = defineProps({ 
		zIndexNum: {
			type: Number, 
			default: 1
		},
		handleFlag: {
			type: Boolean, 
			default: true
		}
	}); 
	// 开通vip对象
	const payTotalInfo = ref({ 
		"openVip":false,
		'saleFiffVip':0, // salePriceTotal与vipPriceTotal差价 
		'totalPay':0, // 实际要支付的总价格
		'totalPayVip':0 // 开通vip要支付的并且要用微信支付才可以 
	})
	const benefitVipRef = ref()
	const showCartPop = ref(false)
	const badgeValue = ref(0)
	const totalPrice = ref(0)
	const totalVipPrice = ref(0)
	const totalNum = ref(0) 
	const goodsList = ref([])
	const storeCardInfo = ref({ })  
	
	const initDataNav = () => {
		storeCardInfo.value =  uni.getStorageSync('cardInfo') 
		let shopInfo = uni.getStorageSync('shopInfo')
		if(shopInfo.isPriceVipPrice){  // isPriceVipPrice是否要有会员余额才可享受权益会员
			if(storeCardInfo.value.currentAmtAct > 0 && storeCardInfo.value.memberIsPayCard == 1){
				storeCardInfo.value.memberIsPayCard = '1'
			}else{
				storeCardInfo.value.memberIsPayCard = '0'
			}
		}
		payTotalInfo.value.totalPayVip = storeCardInfo.value.payCardAmt 
		console.log('totalPrice.value:',totalPrice.value)
		console.log('totalVipPrice.value:',totalVipPrice.value)
		payTotalInfo.value.saleFiffVip = numDiffFun(totalPrice.value,totalVipPrice.value) // 当前商品的销售价格与vip价格的差价  
		payTotalInfo.value.openVip = false
	} 
	
	// 清空购物车
	const clearGoods = () => {  
		// 自己主动清楚
		// badgeValue.value = 0
		// totalPrice.value = 0
		// totalVipPrice.value = 0
		// totalNum.value = 0
		// goodsList.value = [] 
		emit('clearCart', '清空购物车');
		showCartPop.value = false
	}
	
	// 购物车弹窗
	const openShowGoods = () => {
		if(!props.handleFlag){
			return
		} 
		console.log('openShowGoods',goodsList.value)
		// goodsList.value.forEach((gitem,gindex)=>{
		// 	gitem?.packageOthList.forEach((item,index)=>{
		// 		//  如果
		// 	})
		// }) 
		emit('updat:zIndexNum', 10076 );
		showCartPop.value = true  
		nextTick(()=>{
			if(payTotalInfo.value.openVip){
				benefitVipRef.value.initStatus(true)
			} 
		}) 
	}    
	
	// 开通vip
	const onceClick = () => {  
		console.log('min通知购物车调整价格')
		payTotalInfo.value.openVip = true 
	}
	
	const updateVipFlag = (checkFlag) => { 
		console.log('通知购物车调整价格')
		if(!checkFlag){
			payTotalInfo.value.openVip = false
		}else{
			payTotalInfo.value.openVip = true
		}
	}
	
	// 初始化购物车
	const toRefresh = () => {
		let cartList = uni.getStorageSync('cartList')
		badgeValue.value = 0
		totalPrice.value = 0
		totalVipPrice.value = 0
		totalNum.value = 0
		goodsList.value = []
		cartList.forEach((item, index) => {
			if (item.qty > 0) {
				// 规格价格特殊处理
				if(item?.specsOthList?.length > 0){
					item.specsOthList.forEach((specsitem,specsindex)=>{
						specsitem?.priceList.forEach((priitem,priindex)=>{
							if(priitem.check){
								totalPrice.value = numAddFun(totalPrice.value, numMultiFun(specsitem.qty, priitem.salePrice))
								totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(specsitem.qty, priitem.vipPrice))   
								// console.log('totalPrice.value',totalPrice.value)
							}
						}) 
					}) 
				}else if(item?.packageOthList?.length > 0){
					// 套餐价格
					item.packageOthList.forEach((packageitem,packageindex)=>{
						totalPrice.value = numAddFun(totalPrice.value, numMultiFun(packageitem.qty, packageitem.salePrice))
						totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(packageitem.qty, packageitem.vipPrice))  
					})  
				}else{
					// 常规单品价格
					totalPrice.value = numAddFun(totalPrice.value, numMultiFun(item.qty, item.salePrice))
					totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(item.qty, item.vipPrice))  
				}
				totalNum.value += 1 
				badgeValue.value += item.qty  
				goodsList.value.push(item)
			} 
			// if (item.qty > 0) { 
			// 	totalNum.value += 1 
			// 	badgeValue.value += item.qty 
			// 	totalPrice.value = numAddFun(totalPrice.value, numMultiFun(item.qty, item.salePrice))  
			// 	totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(item.qty, item.vipPrice))   
			// 	goodsList.value.push(item)
			// }
		}) 
		payTotalInfo.value.saleFiffVip = numDiffFun(totalPrice.value,totalVipPrice.value)    
		// console.log('toRefresh-goodsList.value:', goodsList.value)
	}
	
	// 统一计算底部数据栏(操作 加 减 时触发)
	const computeNav = () => {
		const filteredList = goodsList.value.filter(item => item.qty > 0);
		// console.log('filteredList', filteredList) 
		badgeValue.value = 0
		totalPrice.value = 0
		totalVipPrice.value = 0
		totalNum.value = 0
		filteredList.forEach((item, index) => {
			if (item.qty > 0) { 
				// 规格价格特殊处理
				if(item?.specsOthList?.length > 0){
					item.specsOthList.forEach((specsitem,specsindex)=>{
						specsitem?.priceList.forEach((priitem,priindex)=>{
							if(priitem.check){
								totalPrice.value = numAddFun(totalPrice.value, numMultiFun(specsitem.qty, priitem.salePrice))
								totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(specsitem.qty, priitem.vipPrice))   
								console.log('totalPrice.value',totalPrice.value)
							}
						}) 
					}) 
				}else if(item?.packageOthList?.length > 0){
					// 套餐价格
					item.packageOthList.forEach((packageitem,packageindex)=>{
						totalPrice.value = numAddFun(totalPrice.value, numMultiFun(packageitem.qty, packageitem.salePrice))
						totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(packageitem.qty, packageitem.vipPrice))  
					})  
				}else{
					// 常规单品价格
					totalPrice.value = numAddFun(totalPrice.value, numMultiFun(item.qty, item.salePrice))
					totalVipPrice.value = numAddFun(totalVipPrice.value, numMultiFun(item.qty, item.vipPrice))  
				}
				totalNum.value += 1 
				badgeValue.value += item.qty  
			}
		}) 
		goodsList.value = filteredList; 
		payTotalInfo.value.saleFiffVip = numDiffFun(totalPrice.value,totalVipPrice.value)  
	}
	
	
	// 单品数量处理
	const valChange = (qty, goodItem, index) => {
		// console.log('goodItem', goodItem)  
		computeNav() 
		// 通知父亲修改    
		emit('goodsItemChange', {...goodItem}); 
	} 
	
	// 规格数量处理
	const valChangeSpecs = (qty, specsitem, specsindex, bigItem) => { 
		// 先移除里面小于等于0的数据 (同套餐写法一直即可)
		goodsList.value.forEach((gitem,gindex) => { 
			let goodsqty = 0
			if(gitem.specsOthList){
				let specsOthList = []
				gitem.specsOthList.filter((spitem) => {
				    if (spitem.qty > 0 ) { 
				        specsOthList.push(spitem)
						goodsqty += spitem.qty;  
				    } 
				})
				goodsList.value[gindex].specsOthList = specsOthList
				gitem.qty = goodsqty
			} 
		})    
		computeNav()
		// 通知父亲修改 
		emit('goodsItemChange', {...bigItem});  
	} 
	
	// 套餐数量处理
	const valChangePack = (qty, goodItem, index,bigItem) => {
		console.log('goodItem', goodItem) 
		console.log('goodsList.value', goodsList.value) 
		// return
	    goodsList.value.forEach((gitem) => {
	        let goodsqty = 0;
			if(gitem.packageOthList){
				gitem.packageOthList = gitem?.packageOthList?.filter((pitem) => {
				    if (pitem.qty > 0) {
				        goodsqty += pitem.qty; 
						return true;
				    }  
					return false; 
				});
				gitem.qty = goodsqty; // 将累加的 qty 赋值给 gitem.qty
			} 
	    }); 			
		// // goodsList.value.forEach((gitem) => { gitem.packageOthList = gitem.packageOthList.filter(pitem => pitem.qty !== 0); }); 
		// console.log('goodsList.value', goodsList.value) 
		// return
		computeNav()
		// 通知父亲修改
		emit('goodsItemChange', {...bigItem}); 
		// console.log('payTotalInfo.value.saleFiffVip:',payTotalInfo.value.saleFiffVip)
		// console.log('new-goodsList:', goodsList.value)
	} 
	
	// 处理规格下  相同商品，不同规格，价格不同问题
	const specsHandlePrice = (specsitemList) => {
		let result = 0
		console.log('specsitemList：',specsitemList)
		specsitemList?.priceList.forEach((item,index)=>{
			if(item.check){
				result = item.salePrice
			}
		})
		return result
	} 
 
	// 去结算
	const toPay = async() => {
		if(!props.handleFlag){ 
			uni.showToast({ title: '请先扫描桌台二维码后再继续下单', icon: 'none' })
			return
		} 
		// 结算前需要的业务逻辑
		// 1.有结算的商品 2.开台与否  3.订阅通知-不要了   
		console.log('storeCart.cartList:', goodsList.value)  
		if(goodsList.value.length <= 0){ 
			uni.showToast({ title: '请选择商品结算', icon: 'none' })
			return
		}
		// console.log('allDetails-pre：',goodsList.value)
		const result = await initTableInfo() // result.consumeCode 说明开台了
		console.log('result：',result) 
		if(result.consumeCode){
			// 构造商品结构再 套餐先处理再加单品
			console.log('goodsList:',goodsList.value) 
			// let detailModal = {  "itemCode": "",   "doType": "add", "indexStr": "1",//排序  "itemType": "1",// 1 单品 2 套擦 3 套餐  "goodsPriceCode": "", //套餐编号 "goodsCode": "",//商品编号 "goodsName": "",  "uomCode": "", "uomName": "",  "flavor": "",  "salePrice": "", "vipPrice": "", "orderQty": "",  "producePoint": "", "isUseGold": "",   "saleCoins": "", 	"percentPrice": "",//套餐明细比例价格 "vipPercentPrice": "",//套餐明细比例价格 "isJoinMinConsume":'', "type": "0" // 0 正常  1他人    } 
			// 套餐需要的数据结构
			// let detailModalPack = {  "itemCode": "", "goodsCode": "", "goodsName": "", "uomCode": "", "uomName": "", "salePrice": "",  "vipPrice": "",  "isUseGold": "", "saleCoins": "", "isJoinMinConsume": "", "producePoint": "",  "flavor": "",  "indexStr": 0, "doType": "add", "goodsPriceCode": "",  "orderQty": 1,  "itemType": "", "percentPrice":'',  "vipPercentPrice":''  } 
			let detailListPack = [] // 套餐
			let detailList = [] // 单品 
			let indexStr = 0
			// 先套餐  后单品
			goodsList.value.forEach((item,index)=>{
				indexStr += 1
				if(item?.packageOthList?.length > 0){
					// 套餐
					item?.packageOthList?.forEach((packitem,packindex)=>{ 
						// if(packindex === 0){ 
							indexStr = packindex + indexStr
							let packBig = {} 
							packBig.itemType = 2  // 1 单品 2 套餐 3 套餐下单品 
							packBig.indexStr =  indexStr
							packBig.fold = "0"
							packBig.orderQty = packitem.qty // item.qty  
							packBig.goodsCode = packitem.goodsCode //
							packBig.goodsPriceCode = item.goodsCode //
							packBig.goodsName = packitem.goodsName
							packBig.uomCode = packitem['priceList'][0].uomCode
							packBig.uomName =  packitem['priceList'][0].uomName
							packBig.salePrice = packitem.salePrice 
							packBig.vipPrice = packitem.vipPrice 
							packBig.isUseGold =  packitem.isUseGold 
							packBig.isUseBalance = packitem.isUseBalance
							packBig.saleCoins = packitem.saleCoins 
							packBig.isJoinMinConsume = packitem['priceList'][0].isJoinMinConsume 
							packBig.producePoint = packitem['priceList'][0].producePoint 
							packBig.goodsTypeOrg = packitem.goodsType 
							packBig.flavor = ''  
							packBig.doType = "add"  
							packBig.percentPrice = ''
							packBig.vipPercentPrice = ''
							packBig.attachment = packitem.attachment
							detailListPack.push(packBig)
						// }
						packitem?.['priceList'][0]?.detail.forEach((ditem,dindex)=>{
							ditem?.goodsDetail?.forEach((gitem,gindex)=>{  
								let detailModalPack = {}
							    // 固定套餐 全部都要
							    if(ditem.operType === '1' ){ 
								    detailModalPack.itemType = 3  // 1 单品 2 套餐 3 套餐下单品
								    detailModalPack.indexStr =  indexStr
								    detailModalPack.fold = "0"
								    detailModalPack['orderQty'] = gitem.defaultQty 
								    detailModalPack.vipPrice =  '' 
								    detailModalPack.goodsCode = gitem.goodsCode
								    detailModalPack.goodsPriceCode = item.goodsCode
								    detailModalPack.goodsName = gitem.goodsName
								    detailModalPack.uomCode = gitem.uomCode
							        detailModalPack.uomName = gitem.uomName
								    detailModalPack.salePrice = gitem.salePrice  
								    detailModalPack.isUseGold = '' //
								    detailModalPack.saleCoins = '' // packitem.saleCoins 
								    detailModalPack.isJoinMinConsume =  '' //packitem['priceList'][0].isJoinMinConsume 
								    detailModalPack.producePoint = gitem.producePoint 
								    detailModalPack.flavor = ''
								    detailModalPack.doType = "add"  
								    detailModalPack.percentPrice = ''
								    detailModalPack.vipPercentPrice = '' 
								    detailListPack.push(detailModalPack)  
							    }
							    // 可选种类 判断 check: true
							    if(ditem.operType === '0' && ditem.choiceType === '1' && gitem.check){
							 	    detailModalPack.itemType = 3  // 1 单品 2 套餐 3 套餐下单品
							 	    detailModalPack.indexStr =  indexStr
							 	    detailModalPack.fold = "0"
							 	    detailModalPack['orderQty'] = gitem.defaultQty 
							 	    detailModalPack.vipPrice =  '' 
							 	    detailModalPack.goodsCode = gitem.goodsCode
							 	    detailModalPack.goodsPriceCode = item.goodsCode
							 	    detailModalPack.goodsName = gitem.goodsName
							 	    detailModalPack.uomCode = gitem.uomCode
							 	    detailModalPack.uomName = gitem.uomName
							 	    detailModalPack.salePrice = gitem.salePrice  
							 	    detailModalPack.isUseGold = '' //
							 	    detailModalPack.saleCoins = '' // packitem.saleCoins 
							 	    detailModalPack.isJoinMinConsume =  '' //packitem['priceList'][0].isJoinMinConsume 
							 	    detailModalPack.producePoint = gitem.producePoint  
							 	    detailModalPack.flavor = ''
							 	    detailModalPack.doType = "add"  
							 	    detailModalPack.percentPrice = ''
							 	    detailModalPack.vipPercentPrice = ''
							 	    detailListPack.push(detailModalPack)  
							    }
							    // 可选商品数量
							    if(ditem.operType === '0' && ditem.choiceType === '0' && gitem.defaultQty > 0){
								    detailModalPack.itemType = 3  // 1 单品 2 套餐 3 套餐下单品
								    detailModalPack.indexStr =  indexStr
								    detailModalPack.fold = "0"
								    detailModalPack['orderQty'] = gitem.defaultQty 
								    detailModalPack.vipPrice =  '' 
								    detailModalPack.goodsCode = gitem.goodsCode
								    detailModalPack.goodsPriceCode = item.goodsCode
								    detailModalPack.goodsName = gitem.goodsName
								    detailModalPack.uomCode = gitem.uomCode
								    detailModalPack.uomName = gitem.uomName
								    detailModalPack.salePrice = gitem.salePrice  
								    detailModalPack.isUseGold = '' //
								    detailModalPack.saleCoins = '' // packitem.saleCoins 
								    detailModalPack.isJoinMinConsume =  '' //packitem['priceList'][0].isJoinMinConsume 
								    detailModalPack.producePoint = gitem.producePoint  
								    detailModalPack.flavor = ''
								    detailModalPack.doType = "add"  
								    detailModalPack.percentPrice = ''
								    detailModalPack.vipPercentPrice = ''
								    detailListPack.push(detailModalPack)  
							    }  
						    }) 
						}) 
					}) 
				} 
				else if(item?.specsOthList?.length > 0){ 
					//规格 
					item?.specsOthList?.forEach((specsitem,specsindex)=>{ 
						let detailModal = {}
						detailModal.flavor = '' 
						// goodsFlavor规格有多个
						if(specsitem?.['goodsFlavor']?.length > 0){
						    specsitem?.['goodsFlavor'].forEach((gfitem,gfindex)=>{
						    	gfitem?.defCheck?.forEach((defitem,defindex)=>{  
						    		detailModal.flavor += defitem + '、'
						        }) 
						    })
						}

						// priceList 必然是单选只有一个check
						specsitem?.['priceList'].forEach((pitem,pindex)=>{
							if(pitem.check){
								detailModal.flavor += pitem.uomName
								detailModal.uomCode = pitem.uomCode
								detailModal.uomName = pitem.uomName
								detailModal.producePoint = pitem.producePoint
								detailModal.isUseBalance = pitem.isUseBalance  
								detailModal.isUseGold = pitem.isUseGold  
								detailModal.isJoinMinConsume = pitem.isJoinMinConsume  
								detailModal.salePrice = pitem.salePrice
								detailModal.vipPrice = pitem.vipPrice
							}
						}) 
						detailModal.attachment = specsitem.attachment
						detailModal.itemCode = ""
						detailModal.doType = "add"
						detailModal.indexStr = indexStr 
						detailModal.itemType = '1'  // 1 单品 2 套餐 3 套餐下单品
						detailModal.goodsPriceCode = specsitem.goodsCode
						detailModal.goodsCode = specsitem.goodsCode
						detailModal.goodsName = specsitem.goodsName  
						detailModal.orderQty = specsitem.qty 
						detailModal.saleCoins = item.saleCoins
						detailModal.goodsTypeOrg = specsitem.goodsType  
						detailModal.percentPrice = '' // 比例价格
						detailModal.vipPercentPrice = '' // 比例价格 
						detailModal.type = 0 
						detailList.push(detailModal)
					}) 
				} else {
					let detailModal = {}
					detailModal.attachment = item.attachment
					detailModal.itemCode = ""
					detailModal.doType = "add"
					detailModal.indexStr = indexStr // + 1 + ''
					detailModal.itemType = '1'  // 1 单品 2 套餐 3 套餐下单品
					detailModal.goodsPriceCode = item.goodsCode
					detailModal.goodsCode = item.goodsCode
					detailModal.goodsName = item.goodsName
					detailModal.uomCode = item.priceList[0].uomCode
					detailModal.uomName = item.priceList[0].uomName 
					detailModal.flavor = '' // 单品没有规格
					detailModal.salePrice = item.salePrice
					detailModal.vipPrice = item.vipPrice
					detailModal.orderQty = item.qty
					detailModal.producePoint = item.priceList[0].producePoint 
					detailModal.isUseGold = item.priceList[0].isUseGold  
					detailModal.isUseBalance = item.priceList[0].isUseBalance 
					detailModal.saleCoins = item.saleCoins
					detailModal.goodsTypeOrg = item.goodsType
					detailModal.percentPrice = '' //套餐明细比例价格
					detailModal.vipPercentPrice = '' //套餐明细比例价格
					detailModal.isJoinMinConsume = item.priceList[0].isJoinMinConsume
					detailModal.type = 0 
					detailList.push(detailModal)
				}  
			})
			let allDetails = [...detailListPack, ...detailList]
			console.log('allDetails：',allDetails)
			showCartPop.value = false
			uni.removeStorageSync('orderPayInfo')
			uni.navigateTo({
				url: '/pagesOrder/view/pay/index?goodsList=' + encodeURIComponent(JSON.stringify(allDetails)) + '&isPreVip=' + payTotalInfo.value.openVip
			})  
		}else{
			uni.showToast({ title: '请联系服务员开台!谢谢', icon: 'none' })
		} 
	}
	
	// 过滤回显  
	const filterPackFlavor = (item) => {
		let favorstr = ''
		let favorList = []
		item.priceList.forEach((item)=>{
			item.detail.forEach((deitem)=>{
				deitem.goodsDetail.forEach((goodsitem)=>{
					if(goodsitem?.goodsFlavor?.length > 0){
						goodsitem.goodsFlavor.forEach((gfitem)=>{ 
							if(gfitem?.defCheck){
								favorList = favorList.concat(gfitem.defCheck)
							} 
						})
					} 
				})
			})
		})
		console.log('filterPackFlavor:',item)
		favorstr = favorList.join(',')
		return favorstr
	}
	
	defineExpose({
		toRefresh,initDataNav
	});
</script>

<style scoped lang="scss">
	.good-cart-view{
		height:80rpx;position: fixed;bottom: 20rpx;left: 24rpx;width: 702rpx;border-radius: 60rpx;
		&.qunqing{
			background: #3A3A3A;
		}
		&.other{
			background: #e7e7e7;
		}
	}
	
	.carr-num-view{
		width: 72rpx;position: relative;
		.num-badge{
			position: absolute;top: -2rpx;right: -20rpx;
			.qunqing{
				color: #212121;
			}
			.other{
				color: #ffffff;
			}
		}
	}
	
	.carr-content-view{
		width: calc(702rpx - 180rpx - 72rpx);overflow-x: hidden;
		
		.fix-w{
			width: 20rpx;
		}
		.dol{
			
			font-size: 20rpx;
			&.qunqing{
				color: #FFFFFF;
			}
			&.other{
				color: #212121;
			}
		}
		.dol-money{
			font-size: 34rpx;
			font-weight: 800;
			&.qunqing{
				color: #FFFFFF;
			}
			&.other{
				color: #212121;
			}
		}
		.dol-total-money{
			font-size: 34rpx;
			font-weight: 800;
			&.qunqing{
				color: #FFFFFF;
			}
			&.other{
				color: #212121;
			}
		}
		.fix-center-w{
			width: 8rpx;
		}
		
		.open-vip-view{
			font-size: 20rpx;
			.vip-total{
				color: #999999;
			}
			.vip-money{
				margin-left: 5rpx;
				color: #FE0190;
			}
			.vip-badge{ 
				color: #999999;
			}
		}
		
		.fix-end-w{
			width: 8rpx;
		}
	}
	
	.cart-pay{
		width: 180rpx;
		height: 80rpx;
		background: var(--dt-backcolorPink);
		border-radius: 40rpx;
		line-height: 80rpx;
		text-align: center;
		color: var(--maincolor);
		font-weight: bold;
		font-size: 32rpx;
	}
	
	.cart-pay-stop{
		width: 180rpx;
		height: 80rpx;
		background: #7b7b7b;
		border-radius: 40rpx;
		line-height: 80rpx;
		text-align: center;
		color: var(--maincolor);
		font-weight: bold;
		font-size: 32rpx;
	}
	
	
	.cart-pop{
		width: 100vw;overflow-y: scroll;
	}
	.cart-pop-view{
		background-color: #FFFFFF;
	}
	
	.clear-view{
		margin: 34rpx 24rpx;
		.clear-icon{
			width: 28rpx;height: 28rpx;
		}
		.clear-name{
			margin-left: 10rpx;color: #666666;
		}
	}
	
	.pop-goods-view{
		max-height: 60vh;
		overflow-x: hidden;
		overflow-y: scroll;
	}
	
	.pop-package-view{
		padding: 0 24rpx;
	} 
	
	.pop-flavor-view{
		width:562rpx; 
		.pop-sub-name{
			line-height: 30rpx;color: #212121;
		}
		.pop-flavor{
			font-size: 22rpx;
			line-height: 30rpx;color: #666666;
			// height: 30rpx;
			width: 560rpx;
			overflow-x: hidden;
		}
	}
	
	.pop-price-num{
		color: #212121;
		font-weight: bold;
		font-size: 36rpx;
		line-height: 52rpx;
		height: 52rpx;
	}
	
	.pop-specs-view{
		padding: 0 24rpx;
	}
	
	.pop-public-img{
		width: 120rpx;height: 120rpx;border-radius: 10rpx;
	}
	
	.pop-flavor-specs{
		color: #666666;line-height: 30rpx;font-size: 24rpx;width: 562rpx;
	}
	
	.pop-specs-p-n{
		color: #212121;font-weight: bold;font-size: 36rpx;line-height: 52rpx;height: 52rpx;
	}
	
	.pop-single-view{
		padding: 0 24rpx;
	}
	.pop-single-p-n{
		color: #212121;font-weight: bold;font-size: 36rpx;line-height: 52rpx;height: 52rpx;
	}
	.dol-total-j{
		color: #999999;
		font-size: 20rpx;
		margin-top: 6rpx;
	}
	.bc-fix-20{
	    background-color: #F2F2F2;
	}
</style>